49#define WOLF_SOLVER_CREATE(SolverClass) \
50 static SolverManagerPtr create(const ProblemPtr& _problem, \
51 const YAML::Node& _input_node, \
52 const std::vector<std::string>& _folders_schema = {}) \
54 if (not _folders_schema.empty()) \
56 auto server = yaml_schema_cpp::YamlServer(_folders_schema); \
57 server.setYaml(_input_node); \
58 if (not server.applySchema(#SolverClass)) \
60 WOLF_ERROR(server.getLog()); \
63 return std::shared_ptr<SolverClass>(new SolverClass(_problem, server.getNode())); \
65 return std::shared_ptr<SolverClass>(new SolverClass(_problem, _input_node)); \
67 static SolverManagerPtr create(const ProblemPtr& _problem, \
68 const std::string& _yaml_filepath, \
69 const std::vector<std::string>& _folders_schema) \
71 auto server = yaml_schema_cpp::YamlServer(_folders_schema, _yaml_filepath); \
72 if (not server.applySchema(#SolverClass)) \
74 WOLF_ERROR(server.getLog()); \
77 return create(_problem, server.getNode(), {}); \
96 GAUSS_TUCAN_ONLY_POSITION = 5
147 std::thread solver_thread_;
157 SolverManager(
const ProblemPtr& _problem,
const YAML::Node& _params);
161 static SolverManagerPtr
autoSetup(
const ProblemPtr& _problem,
162 const std::string& _input_yaml_file,
163 std::vector<std::string> _primary_schema_folders,
164 bool _skip_yaml_validation =
false);
168 static SolverManagerPtr
autoSetup(
const ProblemPtr& _problem,
169 YAML::Node _param_node,
170 std::vector<std::string> _primary_schema_folders,
171 bool _skip_yaml_validation =
false);
246 const LocalParametrizationBasePtr& local_param) const final;
294 virtual
bool check(
std::
string prefix = "") const final;
318 virtual
void addFactor(const FactorBasePtr& fac_ptr) final;
322 virtual
void removeFactor(const FactorBasePtr& fac_ptr) final;
326 virtual
void addStateBlock(const StateBlockPtr& state_ptr) final;
330 virtual
void removeStateBlock(const StateBlockPtr& state_ptr) final;
334 virtual
void updateStateBlockState(const StateBlockPtr& state_ptr) final;
338 virtual
void updateStateBlockStatus(const StateBlockPtr& state_ptr) final;
342 virtual
void updateStateBlockLocalParametrization(const StateBlockPtr& state_ptr) final;
401 const LocalParametrizationBasePtr& local_param) const = 0;
442 virtual
void run() final;
446 virtual
void stop() final;
Profiling of a periodic task: number of calls, duration (accumulated, average, max,...
Definition: profiling_unit.h:31
Solver manager for WOLF.
Definition: solver_manager.h:84
virtual int numStateBlocksEstimated() const final
Returns the number of estimated state blocks: registered and not fixed.
Definition: solver_manager.cpp:608
ProfilingUnit profiling_cov_
Covariances computation.
Definition: solver_manager.h:142
virtual bool hasLocalParametrization(const StateBlockPtr &st) const final
Returns whether a state block has a local parametrization in the solver.
Definition: solver_manager.cpp:573
ProblemPtr wolf_problem_
Wolf problem.
Definition: solver_manager.h:134
virtual void stop() final
Stops the solver loop and joins its thread.
Definition: solver_manager.cpp:655
ProfilingUnit profiling_total_
Profiling units of solve(), solving, problem update, state update and covariances computation.
Definition: solver_manager.h:138
virtual int sizeFactorsDerived() const =0
Returns the total residual size of the factors in the derived solver.
virtual void updateStateBlockStatusDerived(const StateBlockPtr &state_ptr)=0
Updates the fixed/unfixed status of a state block in the derived solver.
virtual int sizeStateBlocksEstimatedDerived() const =0
Returns the total size of the estimated state blocks in the derived solver.
CovarianceBlocksToBeComputed
Enumeration of covariance blocks to be computed.
Definition: solver_manager.h:89
virtual bool isFactorRegisteredDerived(const FactorBasePtr &fac_ptr) const =0
Returns whether a factor is in the derived solver.
std::set< StateBlockPtr > floating_state_blocks_
State blocks not involved in any factor.
Definition: solver_manager.h:300
virtual Eigen::VectorXd & getAssociatedMemBlock(const StateBlockPtr &state_ptr)
Returns the state vector of a registered state block used by the solver.
Definition: solver_manager.cpp:497
ProfilingUnit profiling_state_
State update.
Definition: solver_manager.h:141
ProfilingUnit profiling_update_
Problem update.
Definition: solver_manager.h:140
virtual bool check(std::string prefix="") const final
Checks the consistency of the solver manager and of the derived solver.
Definition: solver_manager.cpp:718
YAML::Node getParams() const
Returns a copy of the YAML parameters.
Definition: solver_manager.cpp:624
virtual double initialCost() const =0
Returns the initial cost of the last solve.
ReportVerbosity getVerbosity() const
Returns the verbosity of the solver report.
Definition: solver_manager.cpp:533
virtual void run() final
Runs the solver loop in a separate thread.
Definition: solver_manager.cpp:644
std::chrono::high_resolution_clock::time_point last_cov_time_
Time of the last covariances computation.
Definition: solver_manager.h:460
const double * getAssociatedMemBlockPtr(const StateBlockPtr &state_ptr) const
Returns a pointer to the state vector of a registered state block used by the solver.
Definition: solver_manager.cpp:509
std::map< StateBlockPtr, FactorBasePtrList > state_blocks_2_factors_
Factors of each registered state block.
Definition: solver_manager.h:298
virtual void updateStateBlockLocalParametrizationDerived(const StateBlockPtr &state_ptr)=0
Updates the local parametrization of a state block in the derived solver.
virtual double finalCost() const =0
Returns the final cost of the last solve.
virtual bool checkDerived(std::string prefix="") const =0
Checks the consistency of the derived solver.
double getPeriod() const
Returns the period of the solver loop.
Definition: solver_manager.cpp:629
CovarianceBlocksToBeComputed cov_enum_
Covariance blocks computed in the solver loop.
Definition: solver_manager.h:458
virtual int sizeFactors() const final
Returns the total residual size of the registered factors.
Definition: solver_manager.cpp:587
bool compute_cov_
Whether the covariances are computed in the solver loop.
Definition: solver_manager.h:457
virtual unsigned int iterations() const =0
Returns the number of iterations of the last solve.
static SolverManagerPtr autoSetup(const ProblemPtr &_problem, const std::string &_input_yaml_file, std::vector< std::string > _primary_schema_folders, bool _skip_yaml_validation=false)
Creates a solver from a YAML file (see the YAML node version)
Definition: solver_manager.cpp:50
double getCovPeriod() const
Returns the period of the covariances computation in the solver loop.
Definition: solver_manager.cpp:634
virtual int numFactors() const final
Returns the number of registered factors.
Definition: solver_manager.cpp:582
virtual int numStateBlocks() const final
Returns the number of state blocks (registered and floating)
Definition: solver_manager.cpp:594
virtual int sizeStateBlocksEstimated() const final
Returns the total size of the estimated state blocks: registered and not fixed.
Definition: solver_manager.cpp:616
const ProfilingUnit & getProfilingUpdate() const
Returns the profiling of the problem update.
Definition: solver_manager.cpp:873
const ProfilingUnit & getProfilingTotal() const
Returns the profiling of solve(): update problem, solve and update state.
Definition: solver_manager.cpp:863
virtual bool hasLocalParametrizationDerived(const StateBlockPtr &st) const =0
Returns whether a state block has a local parametrization in the derived solver.
bool stopping_
Whether the solver loop has to stop.
Definition: solver_manager.h:461
virtual void addStateBlockDerived(const StateBlockPtr &state_ptr)=0
Adds a state block to the derived solver.
virtual int numFactorsDerived() const =0
Returns the number of factors in the derived solver.
virtual bool failed() const =0
Returns whether the last solve failed.
const ProfilingUnit & getProfilingCov() const
Returns the profiling of the covariances computation.
Definition: solver_manager.cpp:883
SolverManager(const ProblemPtr &_problem)
Constructor with default params_.
virtual bool computeCovariances() final
Computes the covariances of the blocks specified in the parameters. Returns whether it succeeded.
Definition: solver_manager.cpp:271
std::map< StateBlockPtr, Eigen::VectorXd > state_blocks_
Registered state blocks and solver states.
Definition: solver_manager.h:297
virtual bool hasThisLocalParametrizationDerived(const StateBlockPtr &st, const LocalParametrizationBasePtr &local_param) const =0
Returns whether a state block has a given local parametrization in the derived solver.
virtual bool isStateBlockRegistered(const StateBlockPtr &state_ptr) const final
Returns whether a state block is registered in the solver.
Definition: solver_manager.cpp:538
virtual bool isStateBlockFixedDerived(const StateBlockPtr &st) const =0
Returns whether a state block is fixed in the derived solver.
YAML::Node params_
YAML parameters.
Definition: solver_manager.h:144
bool getComputeCov() const
Returns whether the covariances are computed in the solver loop.
Definition: solver_manager.cpp:639
std::string solve()
Solves with the verbosity defined in params_.
Definition: solver_manager.cpp:229
virtual int sizeStateBlocks() const final
Returns the total size of the state blocks (registered and floating)
Definition: solver_manager.cpp:599
virtual double totalTime() const =0
Returns the total time of the last solve.
ProblemPtr getProblem()
Returns the wolf problem.
Definition: solver_manager.cpp:224
virtual bool isStateBlockFixed(const StateBlockPtr &st) const final
Returns whether a registered state block is fixed in the solver.
Definition: solver_manager.cpp:554
double cov_period_
Period of the covariances computation in the solver loop.
Definition: solver_manager.h:459
virtual bool isFactorRegistered(const FactorBasePtr &fac_ptr) const final
Returns whether a factor is registered in the solver.
Definition: solver_manager.cpp:549
virtual bool isStateBlockRegisteredDerived(const StateBlockPtr &state_ptr) const =0
Returns whether a state block is in the derived solver.
const ProfilingUnit & getProfilingSolve() const
Returns the profiling of the solving.
Definition: solver_manager.cpp:868
virtual void removeStateBlockDerived(const StateBlockPtr &state_ptr)=0
Removes a state block from the derived solver.
ProfilingUnit profiling_solve_
Solving.
Definition: solver_manager.h:139
virtual void update()
Updates solver's problem according to the wolf_problem.
Definition: solver_manager.cpp:121
void printProfiling(std::ostream &stream=std::cout) const
Prints the profiling of the solver manager (and of the derived solver)
Definition: solver_manager.cpp:888
virtual int numStateBlocksEstimatedDerived() const =0
Returns the number of estimated state blocks in the derived solver.
ReportVerbosity verbose_
Verbosity of the solver report.
Definition: solver_manager.h:456
virtual bool isStateBlockFloating(const StateBlockPtr &state_ptr) const final
Returns whether a state block is floating: not involved in any factor, so kept out of the solver.
Definition: solver_manager.cpp:544
virtual void printProfilingDerived(std::ostream &stream=std::cout) const =0
Prints the profiling of the derived solver.
virtual ~SolverManager()
Destructor.
Definition: solver_manager.cpp:48
std::set< FactorBasePtr > factors_
Registered factors.
Definition: solver_manager.h:299
virtual bool hasThisLocalParametrization(const StateBlockPtr &st, const LocalParametrizationBasePtr &local_param) const final
Returns whether a state block has a given local parametrization in the solver.
Definition: solver_manager.cpp:563
virtual bool computeCovariancesDerived(const CovarianceBlocksToBeComputed blocks)=0
Computes the covariances of the specified blocks in the derived solver.
virtual bool converged() const =0
Returns whether the last solve converged.
virtual bool wasStopped() const =0
Returns whether the last solve was stopped (interrupted by a problem change)
virtual void addFactorDerived(const FactorBasePtr &fac_ptr)=0
Adds a factor to the derived solver.
double period_
Period of the solver loop.
Definition: solver_manager.h:455
virtual std::string solveDerived(const ReportVerbosity report_level)=0
Solves the problem in the derived solver, returning the report.
virtual void removeFactorDerived(const FactorBasePtr &fac_ptr)=0
Removes a factor from the derived solver.
const ProfilingUnit & getProfilingState() const
Returns the profiling of the state update.
Definition: solver_manager.cpp:878
ReportVerbosity
Enumeration for the verbosity of the solver report.
Definition: solver_manager.h:102
Namespace extending Eigen definitions.
Definition: wolf.h:91
Definition: composite.h:251
Definition: capture_base.h:23
WOLF_PTR_TYPEDEFS(CaptureLandmarksExternal)